package io.linfeng.modules.app.controller;

import io.linfeng.common.utils.R;
import io.linfeng.modules.admin.entity.AppUserEntity;
import io.linfeng.modules.app.annotation.Login;
import io.linfeng.modules.app.annotation.LoginUser;
import io.linfeng.modules.app.param.ReadNoticeForm;
import io.linfeng.modules.app.param.RejectNoticeForm;
import io.linfeng.modules.app.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author linfeng
 * @date 2022/11/16 16:55
 */
@RestController
@RequestMapping("app/notice")
@Api(tags = "移动端——IM通知")
public class AppNoticeController {

    @Autowired
    private NoticeService noticeService;


    @Login
    @GetMapping("/list")
    @ApiOperation("获取IM通知列表")
    public R getNoticeList(@LoginUser AppUserEntity user){
        Map<String, Object> map = noticeService.getNoticeList(user.getUid());
        return R.ok().put("data",map);
    }

    @Login
    @PostMapping("/readById")
    @ApiOperation("根据id已读消息")
    public R readById(@RequestBody ReadNoticeForm param){
        noticeService.readById(param);
        return R.ok();
    }

    @Login
    @PostMapping("/reject")
    @ApiOperation("拒绝好友申请")
    public R reject(@RequestBody RejectNoticeForm param){
        noticeService.reject(param);
        return R.ok();
    }

    @Login
    @PostMapping("/delete")
    @ApiOperation("删除好友申请")
    public R delete(@RequestBody ReadNoticeForm param){
        noticeService.removeById(param.getId());
        return R.ok();
    }

}
